<?php

namespace backend\services\goods;

use backend\extensions\ApiBaseService;
use backend\models\goods\cate\GoodsCate;

/**
 * Desc 分类管理服务类
 * @author WMX
 */
class GoodsCateService extends ApiBaseService
{

    /**
     * 列表
     * @param array $params 参数 
     * **/
    public static function getList($params)
    {
        //检索条件
        $list = GoodsCate::getDataAll([], 1, 100000);
        $list['list'] = GoodsCate::arrayTree($list['list']);
        return $list;
    }

    /**
     * 新增
     * @param array $params 参数 
     * * */
    public static function create($params)
    {
        if (GoodsCate::create($params) == false) {
            return self::jsonError('保存失败');
        }
        return self::jsonSuccess($params);
    }

    /**
     * 新增
     * @param array $params 参数 
     * * */
    public static function update($params)
    {
        $condition = ['id' => $params['id']];
        unset($params['id']);
        if (GoodsCate::updateData($params, $condition) === false) {
            return self::jsonError('更新失败');
        }
        return self::jsonSuccess();
    }

    /**
     * 删除
     * @param array $params 参数 
     * * */
    public static function delete($params)
    {
        $condition = ['id' => $params['id']];
        if (GoodsCate::del($condition) == false) {
            return self::jsonError('删除失败');
        }
        return self::jsonSuccess();
    }

    /**
     * 详情
     * @param array $params 参数 
     * **/
    public static function detail($params)
    {
        $condition = ['id' => $params['id']];
        $data = GoodsCate::getDataOne($condition, '', ['id','name','img', 'state', 'sort', 'pid', 'url']);
        return self::jsonSuccess($data);
    }

}
